<div class="view">
<fieldset id="saved_report" class="ui-widget section">
<legend	class="ui-widget-header ui-corner-all">Saved Report</legend>
	<?php 
		$report = $packing_list->report();
		if(count($report) == 0)
			echo "No report is being generated yet";
	?> 
	<?php foreach($report as $_report): ?>
	<div>
		<?php CHtml::link(CHtml::encode($_report->subject),CHtml::normalizeUrl(array('packing_list/viewreport','id'=>$_report->id))); ?>
	</div>
	<?php endforeach; ?>	
</fieldset>
<fieldset id="new_report" class="ui-widget section">
	<legend class="ui-widget-header ui-corner-all">New Report</legend>
	<div class="wide form">
		<div class="row" style="width: 100%;">
			<div class="col">
				<?php echo CHtml::dropDownList('reportType',0,array('packing_list'));?>
			</div>
			<div class="col">
				<?php $this->widget('application.widgets.listicon.ListIcon',array(
                    'icons'=>array(
						array('value'=>'Generate report','icon'=>'ui-icon-note','needtext'=>"true"),
					),
				));?>
			</div>
		</div>
	</div>
<hr />
</fieldset>
</div>
<?php
$cs = Yii::app()->getClientScript();
$viewPackageURL = CHtml::normalizeUrl(array('packing_list/viewpackage','packing_list_id'=>$model->id));
$NewPackageURL = CHtml::normalizeUrl(array('packing_list/NewPackage','packing_list_id'=>$model->id));
$s =<<<EOD
$('div [name="packing_list_icon"]>a:eq(0)').live('click',function(){
    $('fieldset#packing_list_package').append('<hr /><div id="packages_container"></div>');
    var container = $('fieldset#packing_list_package>#packages_container:last');
    $(container).subcontent({
        url:'$NewPackageURL',
        afterShow:function(){
            $(container).find('input[type="submit"]').unbind();
            $(container).find('input[type="submit"]').bind({'click':function(){
                    var newSubmit = $.extend({},$.simplelogform,{afterSubmit:function(data){
                                            $(container).subcontent({
                                                url:'$viewPackageURL?id='+data.id
                                            });
                                        }
                                    });
                    var i=0;
                    var cargo_id = [];
                    $(container).find('#package_do_list').find('input').each(function(){
                        var name = "cargo["+i+"][id]";
                        var value = $(this).attr('cargo_id');
                        cargo_id[name] = value;
                        i++;
                    });
                    newSubmit.Submit($(container).find('form'),cargo_id);
                    return false;
                }
            });
            $(container).find('input#Cancel').click(function(){
                $('fieldset#packing_list_package>#packages_container:last, fieldset#packing_list_package>hr:last').remove();
            });
        }
    });
    return false;
});
EOD;
$cs->registerScript('packing_list#view',$s);
?>